package com.edu.springboot_disk_erban.dao;

import com.edu.springboot_disk_erban.entity.FileBean;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component("FileMapper")
public interface FileDao {
    //增加
    @Insert("insert into fileBean(fileName,filePath,fileSize,fileTime,isDirectory) values(#{fileName},#{filePath},#{fileSize},#{fileTime},#{isDirectory}) ")
    int addFileBean(FileBean fileBean);


    @Insert("insert into collectFile(fileName,filePath,fileSize,fileTime,isDirectory) values(#{fileName},#{filePath},#{fileSize},#{fileTime},#{isDirectory}) ")
    int addCollectFile(FileBean fileBean);

    @Delete("delete from collectFile where filePath=#{filePath}")
    int delCollectFile(String filePath);

    @Insert("insert into rubbishFile(fileName,filePath,fileSize,fileTime,isDirectory) values(#{fileName},#{filePath},#{fileSize},#{fileTime},#{isDirectory}) ")
    int addRubbishFile(FileBean fileBean);

    @Insert("insert into fileBean(fileName,filePath,fileSize,fileTime,isDirectory) values(#{fileName},#{filePath},#{fileSize},#{fileTime},#{isDirectory}) ")
    int addFileBeanFile(FileBean fileBean);
    //删
    @Delete("delete from fileBean where fileId=#{fileId}")
    int deleteById(int fileId);

    //删
    @Delete("delete from fileBean where filePath=#{filePath}")
    int deleteByPath(String  filePath);

    @Delete("delete from rubbishFile where filePath=#{filePath}")
    int deleteRubbishByPath(String  filePath);

    @Delete("delete from rubbishFile where filePath=#{filePath}")
    int deleteByRubbishPath(String  filePath);

    @Delete("delete from collectFile where filePath=#{filePath}")
    int deleteByCollectPath(String  filePath);
    //改
    @Update("update fileBean set fileName=#{fileName},filePath=#{filePath},fileTime=#{fileTime} where fileId=#{fileId}")
    int update(FileBean fileBean);

    //查  查找所有收藏文件
    @Select("select * from collectFile")
    List<FileBean> findCollectAll();

    //查  查找所有用户
    @Select("select * from rubbishFile")
    List<FileBean> findRubbishAll();

    //查  查找所有用户
    @Select("select * from fileBean")
    List<FileBean> findAll();

    //分页查找所有用户
    @Select("select * from fileBean limit #{page},#{size}")
    List<FileBean> findPageAll(int page,int size);

    //查  查找所有用户
    @Select("select * from fileBean where filePath=#{filePath}")
    FileBean findByFilePath(String filePath);
    @Select("select * from rubbishFile where filePath=#{filePath}")
    FileBean findRubbishByFilePath(String filePath);

    @Select("select * from collectFile where filePath=#{filePath}")
    FileBean findByCollectPath(String filePath);

    //查  查找所有用户
    @Select("select * from fileBean where fileId=#{fileId}")
    FileBean findById(int fileId);

    //查 查所有文件见及文件
    @Select("select * from fileBean where filePath like concat('%',#{filePath},'%') order by isDirectory desc, fileTime asc")
    List<FileBean> findBySonPath(String filePath);

    @Select("select * from collectFile where filePath like concat('%',#{filePath},'%')")
    List<FileBean> findCollectBySonPath(String filePath);

    @Select("select * from rubbishFile where filePath like concat('%',#{filePath},'%')")
    List<FileBean> findRubbishBySonPath(String filePath);

    @Select("select * from fileBean where fileName like concat('%',#{fileName},'%')")
    List<FileBean> findSearchName(String fileName);
}
